package org.example.netty.test.nio.netty.chat.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.example.netty.test.nio.netty.chat.bean.OutUserMessage;
import org.example.netty.test.nio.netty.chat.session.GlobalContent;

/**
 * @author zp
 * @version 1.0
 * @description: 处理消息OutUserMessage
 * @date 2023/4/6 18:29
 */
@Slf4j
public class OutUserMessageHandler extends SimpleChannelInboundHandler<OutUserMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, OutUserMessage msg) throws Exception {
        log.debug("退出私聊的消息：{}",msg);
        GlobalContent globalContent = GlobalContent.getInstance();

        String userChat = msg.getUserChatName();
        String sendUserName = msg.getSender();
        globalContent.removeChat(userChat,sendUserName);

        ctx.channel().writeAndFlush(msg);
    }
}
